package com.googlecode.contests_repo.cmd.tools;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;

import com.googlecode.contests_repo.core.users.UserManager;

/**
 * Command-line tool the administrator can use to hash passwords.
 * 
 * @author deni, joro
 */
public class HashPassword {
	
	/**
	 * Outputs the hashcode of the given password.
	 * 
	 * @param args
	 * 		the password to hash
	 * @throws NoSuchAlgorithmException
	 * @throws UnsupportedEncodingException
	 */
	public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException {
		if (args == null || args.length != 1) {
			System.out.println("Usage: hashpassword <password>");
			return;
		}
		
		String password = args[0];
		String hashedPassword = UserManager.getHash(password);
		System.out.println(hashedPassword);
	}
}
